import 'dart:async';

import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_oa/route/routes.dart';

/// 根界面 决定跳转的页面
class PageRoot extends StatefulWidget {
  PageRoot({Key key}) : super(key: key);
  @override
  State<StatefulWidget> createState() => PageRootState();
}

class PageRootState extends State<PageRoot> {
  String result;
  // Flutter主动发送参数给原生
  static const platform = const MethodChannel("getData4Flatter");

  @override
  void initState() {
    super.initState();
    Future.delayed(Duration(seconds: 0), () {
      intentSplash();
//      getData4Flatter('getData');
    });
  }

  Future<Null> getData4Flatter(String method) async {
    try {
      result = await platform.invokeMethod(method);
    } on PlatformException {}
    setState(() {
      print("dart-setState");
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
      child: Image.asset('images/splash.jpg'),
    );
  }

  intentLogin() async {
    String route = '${Routes.login}';
    Routes.router.navigateTo(context, route,
        replace: true, transition: TransitionType.fadeIn);
  }

  intentSplash() async {
    String route = '${Routes.splash}';
    Routes.router.navigateTo(context, route,
        replace: true, transition: TransitionType.fadeIn);
  }
}
